package ebcs.database.service.impl.sys;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ebcs.database.bean.sys.PaAgency;
import ebcs.database.bean.sys.PaUser;
import ebcs.database.bean.sys.PaUserExample;
import ebcs.database.bean.sys.PaUserExample.Criteria;
import ebcs.database.mybatis.dao.sys.PaAgencyMapper;
import ebcs.database.mybatis.dao.sys.PaUserMapper;
import ebcs.database.service.sys.IUserManagerService;

@Service
public class UserManagerServiceImpl implements IUserManagerService {

	@Autowired
	PaUserMapper userDao;
	@Autowired
	PaAgencyMapper agencyDao;
	
	@Override
	public int insert(PaUser paUser) {
		return this.userDao.insert(paUser);
	}

	@Override
	public List<PaUser> seachUserInforByUserNo(String userNo) {
		PaUserExample example = new  PaUserExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserNoEqualTo(userNo);
  		return this.userDao.selectByExample(example);
	}

	@Override
	public int logoutUser(PaUser paUser) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateUserInfor(PaUser paUser) { 
		return this.userDao.updateByPrimaryKeySelective(paUser);
	}

	@Override
	public PaUser seachUserInforByUseId(int userId) { 
  		return this.userDao.selectByPrimaryKey(userId);
	}

	@Override
	public List<PaUser> searchUserInforByAgenId(int agenid) {
		PaUserExample example = new  PaUserExample();
		Criteria criteria = example.createCriteria();
		criteria.andAgenIdEqualTo(agenid);
  		return this.userDao.selectByExample(example);
	}

	@Override
	public PaAgency searchAgencyInforByUserId(String userNo) {
		PaUserExample example = new  PaUserExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserNoEqualTo(userNo);
  		List<PaUser> userList = this.userDao.selectByExample(example);
		PaAgency agency = null;
		if (userList != null && userList.size() > 0) {
			  agency = this.agencyDao.selectByPrimaryKey(userList.get(0).getAgenId());
		}
		return agency;
	}

}
